import request from '@/utils/request'

export const fetchCategoryList = (page, size, keyword) => {
  if (arguments.length === 0) {
    return request({
      url: '/category/list',
      method: 'get',
    })
  } else {
    return request({
      url: '/category/list',
      method: 'get',
      params: {
        page,
        size,
        keyword,
      },
    })
  }
}

export const createCategory = title => {
  return request({
    url: '/category/add',
    method: 'post',
    data: {
      title,
    },
  })
}

export const removeCategory = id => {
  return request({
    url: `/category/${id}`,
    method: 'delete',
  })
}

export const updateCategory = form => {
  return request({
    url: '/category/update',
    method: 'post',
    data: form,
  })
}
